<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="app">
        <nav-bar></nav-bar>

        <hr>

        <nav-bar>
    </div>    

    <!-- 模板内容 -->
    <template id="hello">
        <div>
            <p>{{name}}</p>
            <h2>{{age}}</h2>
            <button @click="modify">修改name</button>
        </div>
    </template>

    <script>
        // 创建一个Vue实例，其本质上就是一个组件，称为根据组件
        new Vue({
            el: '#app',
            data: {
                name:'tom',
                age:18
            },
            components: {
                'NavBar': {
                    template: '#hello',
                    data(){
                        return {
                            name:'alice',
                            age:18
                        }
                    },
                    methods:{
                        modify(){
                            this.name = 'jack'
                        }
                    }
                }
            }
        })
    </script>
</body>
</html>